package org.uek.ships.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uek.shpis.common.Configuration;
import org.uek.shpis.common.transport.Command;

public class Client {
	private static Logger logger = LoggerFactory.getLogger(Client.class);

	public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException {
		Socket socket = new Socket(Configuration.HOST, Configuration.PORT);

		ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
		ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());

		logger.info("Klient polaczany z serwerem ...");
		boolean gameStarted = false;

		while (true) {
			Command command = (Command) objectInputStream.readObject();

			if (command != null) {
				logger.info("Otrzymałem komende : " + command.getMessage());

				if (command.getMessage().equals("Play")) {
					objectOutputStream.writeObject(new Command("Move"));
				}
			}

		}

		// socket.close();

	}
}
